package com.zyf.chapter02.behavior.chain.framework.spring;

/**
 * 使用举例
 * @author yifeng
 */
public class Application {
    public static void main(String[] args) {
        HandlerChain chain = new HandlerChain();
        chain.addHandler(new HandlerA());
        chain.addHandler(new HandlerB());
        chain.handle();

        System.out.println("-----Spring 的 chain 调用---");

        HandlerExecutionChain executionChain = new HandlerExecutionChain();
        executionChain.addHandler(new HandlerA());
        executionChain.addHandler(new HandlerB());
        boolean result = executionChain.applyPreHandle();
        // 这个参数应该是一个全局变量，类似于 ModelAndView
        executionChain.applyPostHandle(Boolean.TRUE);
        if (result) {
            // 如果 applyPreHandle 成功执行所有的执行器，则在这里执行triggerAfterCompletion
            executionChain.triggerAfterCompletion();
        }
    }
}
